// 接受

var express = require('express');
var router = express.Router();
const cinemaApi = require("../api/cinemas");
const TheatersApi = require("../api/theaters");
/* GET home page. */

router.get('/', async function (req, res, next) {
  const data = await cinemaApi.get();
  res.send(data);
});

router.get('/:_id', async function (req, res, next) {
  
  const { _id } = req.params;
  console.log(_id,11111);
  const data = await cinemaApi.getOne({ _id });
  res.send(data);
})
router.post('/', async function (req, res, next) {
  const Nowdata = req.body;
  const data = cinemaApi.add(Nowdata);
  res.send(data);
});
router.put('/:_id', async function (req, res, next) {
  const { _id } = req.params;
  const nowData = req.body;
  const data = await cinemaApi.update({ _id }, nowData);
  res.send(data);
});


router.patch('/updateStatus', async function (req, res, next) {
  const { _id, status } = req.body;
  const data = await cinemaApi.update({ _id }, { status });
  res.send(data);
});



router.delete('/:_id', async function (req, res, next) {
  const { _id } = req.params;
  const data = await cinemaApi.remove({ _id });
  res.send(data);
});


router.get('/all', async function (req, res, next) {
  const data = await cinemaApi.getAll();
  res.send(data);
});

router.get('/:_id/theaters/', async function (req, res, next) {
  const { _id } = req.params;
  const data = await TheatersApi.getBycinemasId(_id);
  res.send(data);
});

// 配置接口
module.exports = router;